<template>
  <div>
         <el-table
      :data="tableData"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      :tree-props="{children: 'children'}"
    >
      <el-table-column prop="id" label="用户编号" sortable width="180"></el-table-column>
      <el-table-column prop="username" label="用户名" sortable width="180"></el-table-column>
      <el-table-column prop="rolename" label="所属角色" sortable width="180"></el-table-column>

      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-button type="success" v-if="scope.row.status ===1">启用</el-button>
          <el-button type="danger" v-else>禁止</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="success" @click="edit(scope.row.uid)">编辑</el-button>
          <el-button type="danger" @click="del(scope.row.uid)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
  background
  layout="prev, pager, next"
  :page-size="size"
  :total="count" @current-change="cpage">
</el-pagination>
  </div>
</template>

<script>
import {mapGetters,mapActions} from 'vuex'
import { successAlert } from '../../../utils/alert'
import { delManager } from '../../../utils/request'
export default {
  mounted() {
    this.requestManager()
    this.requestCount()
  },
  computed:{
     ...mapGetters({
       "tableData":"manager/manager",
       "count":"manager/count",
       "size":"manager/size"
       

     })
  },
  methods: {
      ...mapActions({
        "requestManager":"manager/managerActions",
        "requestCount":"manager/countActions",
        "requestPage":"manager/pageActions"
        
      }),
      cpage(page){
          // console.log(page);
          this.requestPage(page)
          this.requestManager()
      },
      edit(uid){
            this.$emit('edit',uid)
      },
      del(uid){
         this.$confirm('确定要删除吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        delManager({uid}).then(res=>{
          successAlert(res.data.msg)
          this.requestManager()
          this.requestCount()
        })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          }); 
          });
      }
    
},
}
</script>

<style>

</style>